/**
 * 
 */
package com.neal.web.controller;

import java.io.File;
import java.io.IOException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Neal
 * @version 1.0
 * @description
 */
@Controller
@RequestMapping("/upload")
public class UploadController {

	@RequestMapping(method = RequestMethod.GET)
	public String setpForm() {
		return "upload/upload";
	}

	@RequestMapping(method = RequestMethod.POST)
	public String handle(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) throws IllegalStateException, IOException {
		if (!file.isEmpty()) {
			System.out.println(name);
			File file2 = new File(System.getProperty("java.io.tmpdir") +"/"+ file.getOriginalFilename());
			file2.createNewFile();
			file.transferTo(file2);
			return "upload/uploadSuccess";
		} else {
			return "upload/uploadError";
		}
	}
}
